package cn.itqiqi.student_system_java.controller;

import cn.itqiqi.student_system_java.mapper.StudentAllMapper;
import cn.itqiqi.student_system_java.pojo.StudentAll;
import cn.itqiqi.student_system_java.service.StuAllService;
import cn.itqiqi.student_system_java.service.impl.StuAllServiceImpl;
import cn.itqiqi.student_system_java.utils.ResultUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author kevin_琪琪
 */
@RestController
public class StuAllController {

    @Autowired
    private ResultUtils resultUtils;
    @Autowired
    private StuAllServiceImpl stuAllService;

    private final Logger logger = LogManager.getLogger();


    @GetMapping("/stuAll")
    public String stuAll(Long pageNum, Long pageSize) {
        if (pageNum == null || pageSize == null) {
            logger.error("参数不能为空,pageNum：" + pageNum + ",pageSize:" + pageSize);
            return resultUtils.fail(406, "参数不能为空!");
        } else {
            return stuAllService.getStuAll(pageNum,pageSize);
        }
    }

    @GetMapping("/stuByName")
    public String StuByName(Long pageNum, Long pageSize, String selectValue, String queryValue) {
        if (pageNum == null || pageSize == null || selectValue == null || queryValue == null) {
            logger.error("参数不能为空,pageNum：" + pageNum + ",pageSize:" + pageSize + ",selectValue" + selectValue + ",queryValue" + queryValue);
            return resultUtils.fail(406, "参数不能为空!");
        } else {
            switch (selectValue) {
                case "sname":
                    return stuAllService.getStuAllByName(pageNum, pageSize, queryValue);
                case "sex":
                    return stuAllService.getStuAllBySax(pageNum, pageSize, queryValue);
                case "classId":
                    return stuAllService.getStuAllByClassId(pageNum, pageSize, queryValue);
                default:
                    return resultUtils.fail(400, "参数不合法！");
            }
        }
    }
}
